﻿
using System;
using System.Data;
using System.Collections.Generic;

namespace LDSP.BRL
{
    /// <summary>
    /// 企业适用文档责任人关系
    /// </summary>
    public partial class R_CodificationUser : BYFW.BOL.BaseEntity
    {
        public R_CodificationUser()
        {
            m_tableName = "t_r_codification_user";
            m_tblCacheManager.IsEnable = true;
        }

        protected int m_favoriteID = 0;
        protected int m_userID = 0;

        protected R_EnterpriseCodification m_enterpriseCodification = null;
        protected EnterpriseUser m_enterpriseUser = null;

        /// <summary>
        /// 收藏关系ID
        /// </summary>
        public int FavoriteID
        {
            get { return m_favoriteID; }
            set { m_favoriteID = value; }
        }
        /// <summary>
        /// 企业用户ID
        /// </summary>
        public int UserID
        {
            get { return m_userID; }
            set { m_userID = value; }
        }

        public R_EnterpriseCodification EnterpriseCodification
        {
            get
            {
                if (m_enterpriseCodification == null)
                {
                    m_enterpriseCodification = new R_EnterpriseCodification();
                    if (m_favoriteID != 0)
                    {
                        m_enterpriseCodification.GetProperties(m_favoriteID);
                    }
                }
                return m_enterpriseCodification;
            }
        }

        public EnterpriseUser EnterpriseUser
        {
            get
            {
                if (m_enterpriseUser == null)
                {
                    m_enterpriseUser = new EnterpriseUser();
                    if (m_userID != 0)
                    {
                        m_enterpriseUser.GetProperties(m_userID);
                    }
                }
                return m_enterpriseUser;
            }
        }



        protected override void FillContainer()
        {
            base.FillContainer();
            m_container.Add("favoriteID", m_favoriteID);
            m_container.Add("userID", m_userID);
        }

        public override bool GetProperties(System.Data.DataRow record)
        {
            if (!base.GetProperties(record))
            {
                return false;
            }
            m_favoriteID = this.GetIntValue(record, "favoriteID");
            m_userID = this.GetIntValue(record, "userID");
            return true;
        }

        public void DeleteByCodification(string transID, int favoriteID)
        {
            string cond = string.Format("where {0}={1}", DB.GetCol("favoriteID"), DB.GetVal(favoriteID));
            this.DeleteRecord(transID, cond);
        }
        public void DeleteByUser(string transID, int userID)
        {
            string cond = string.Format("where {0}={1}", DB.GetCol("userID"), DB.GetVal(userID));
            this.DeleteRecord(transID, cond);
        }
    }
}
